import pandas as pd


def update_index():
    data = {"name": {"one": "小明", "two": "小红", "three": "小蓝"},
            "age": {"one": 18, "two": 19, "three": 20},
            "height": {"one": 188, "two": 189, "three": 160}
            }
    frame = pd.DataFrame(data)
    # 方式一：reindex
    # 修改行索引
    frame1 = frame.reindex(["three", "two", "six"])
    # print(frame1)
    # 修改列索引
    frame2 = frame.reindex(columns=["age", "name", "height"])
    # print(frame2)
    # 方式二：rename
    frame.rename(columns={"name": "nickname", "age": "ages"}, inplace=True)
    print(frame)
    # 方式三：index赋值
    frame.index = ["a", "b", "c"]
    print(frame)


if __name__ == '__main__':
    update_index()
